package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Scenic;
import cn.wolfcode.luowowo.article.mapper.ScenicMapper;
import cn.wolfcode.luowowo.article.query.ScenicQueryObject;
import cn.wolfcode.luowowo.article.service.IScenicService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ScenicServiceImpl implements IScenicService {

    @Autowired
    private ScenicMapper scenicMapper; //景点mapper 查询数据库

    /**
     * 删除
     * @param id 景点id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Long id) {
        return scenicMapper.deleteByPrimaryKey(id);
    }

    /**
     * 添加
     * @param record 景点对象
     * @return
     */
    @Override
    public int insert(Scenic record) {
        return scenicMapper.insert(record);
    }

    /**
     * 查询所有
     * @param id 景点id
     * @return
     */
    @Override
    public Scenic selectByPrimaryKey(Long id) {
        return scenicMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Scenic> selectAll() {
        return scenicMapper.selectAll();
    }

    /**
     * 更新
     * @param record 景点对象
     * @return
     */
    @Override
    public int updateByPrimaryKey(Scenic record) {
        return scenicMapper.updateByPrimaryKey(record);
    }

    /**
     * 分页高级查询
     * @param qo 查询条件
     * @return
     */
    @Override
    public PageInfo query(ScenicQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Scenic> list = scenicMapper.queryForList(qo);
        return new PageInfo(list);
    }

    /**
     * 查询前五个热门点评
     * @param destId 目的地id
     * @return
     */
    @Override
    public List<Scenic> commentTop5(Long destId) {
        return scenicMapper.commentTop5(destId);
    }

    /**
     * 查询热门
     * @return
     */
    @Override
    public List<Scenic> getHot() {
        return scenicMapper.selectHot();
    }

    /**
     * 通过主题id查询景点
     * @param themeId 主题id
     * @return
     */
    @Override
    public List<Scenic> selectByThemeId(Long themeId) {
        return scenicMapper.queryByThemeId(themeId);
    }

    /**
     * 查询单个
     * @param id 景点id
     * @return
     */
    @Override
    public Scenic get(Long id) {
        return scenicMapper.selectByPrimaryKey(id);
    }

}
